package club.janna.rpcdemo.server.config;

import club.janna.rpcdemo.server.annotation.RPCService;
import club.janna.rpcdemo.server.register.RPCMapping;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class RPCBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        RPCService rpcService = bean.getClass().getAnnotation(RPCService.class);
        if(rpcService != null)
            RPCMapping.register(rpcService.serviceName(), beanName);
        return bean;
    }
}
